package com.alks.function.service.impl.asyncImpl;

import com.alibaba.fastjson2.JSON;
import com.alks.common.service.RedisService;
import com.alks.entity.data.entity.PcCuttingSalary;
import com.alks.function.data.request.PcCuttingSalaryReq;
import com.alks.function.mapper.finance.salary.SalaryFileCreationMapper;
import com.alks.function.service.async.PcCuttingAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.Future;

/**
 * @author:hxl
 * @create: 2024-07-19 16:21
 * @Description:
 */
@Service
@EnableAsync
public class PcCuttingAsyncServiceImpl implements PcCuttingAsyncService {
    @Autowired
    private SalaryFileCreationMapper mapper;
    @Override
    @Async
    public Future<BigDecimal> getPcCuttingSalaryAmtTotal(PcCuttingSalaryReq req) {
        BigDecimal amtTotal = mapper.getPcCuttingSalaryAmtTotal(req);
        Future<BigDecimal> future = new AsyncResult<>(amtTotal);
        return future;
    }

    @Override
    @Async
    public Future<BigDecimal> getPcCuttingSalaryQtyTotal(PcCuttingSalaryReq req) {
        BigDecimal qtyTotal = mapper.getPcCuttingSalaryQtyTotal(req);
        Future<BigDecimal> future = new AsyncResult<>(qtyTotal);
        return future;
    }

    @Autowired
    RedisService redisService;
    private String redisId = "pc-cutting-detail";
    @Async
    public void downPcCuttingSalary(PcCuttingSalaryReq req) {
        redisService.delete(redisId);
        req.setDownFlag("Y");
        List<PcCuttingSalary> salary = mapper.getPcCuttingSalary(req);
        String string = JSON.toJSONString(salary);
        redisService.set(redisId,string);
    }
}
